<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <a-row>
      <a-col :span="6">
        <a-form-model-item label="批次号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="batchNumber">
          <a-input v-model="batchNumber" placeholder="请输入材料批次号"></a-input>
        </a-form-model-item>
      </a-col>
      <a-col :span="6">
        <a-button type="primary" @click="materialSearch" icon="search" style="margin-top: 4px">查询</a-button>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="6">
        <a-form-model-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialCode">
          <a-input v-model="model.materialCode" disabled></a-input>
        </a-form-model-item>
      </a-col>
      <a-col :span="7">
        <a-form-model-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="materialName">
          <a-input v-model="model.materialName" disabled></a-input>
        </a-form-model-item>
      </a-col>
      <a-col :span="7">
        <a-form-model-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="specificationModel">
          <a-input v-model="model.specificationModel" disabled></a-input>
        </a-form-model-item>
      </a-col>
      <a-col :span="4">
        <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
          <a-input v-model="model.unit" disabled></a-input>
        </a-form-model-item>
      </a-col>
    </a-row>
    <a-tabs v-model="activeKey" @change="handleChangeTab" :lazy="false">
      <a-tab-pane key="formula" tab="配方清单" :force-render="true">
        <formulalist ref="formulalistComponent" />
      </a-tab-pane>
      <a-tab-pane key="formulanotice" tab="配方通知单" :force-render="true">
        <formulanotice ref="formulanoticeComponent" />
      </a-tab-pane>
      <a-tab-pane key="packaging" tab="包材清单" :force-render="true">
        <packaging ref="packagingComponent" />
      </a-tab-pane>
      <a-tab-pane key="proplan" tab="生产计划信息" :force-render="true">
        <workshopplan ref="workshopplanComponent" />
      </a-tab-pane>
      <a-tab-pane key="proprocess" tab="生产过程确认" :force-render="true">
        <proprocess ref="proprocessComponent" />
      </a-tab-pane>
      <a-tab-pane key="feeding" tab="生产投料信息" :force-render="true">
        <feeding ref="feedingComponent" />
      </a-tab-pane>
      <a-tab-pane key="inbound" tab="材料入库信息" :force-render="true">
        <inbound ref="inboundComponent" />
      </a-tab-pane>
      <a-tab-pane key="confirm" tab="材料检验信息" :force-render="true">
        <confirm ref="confirmComponent" />
      </a-tab-pane>
      <a-tab-pane key="outbound" tab="材料出库信息" :force-render="true">
        <outbound ref="outboundComponent" />
      </a-tab-pane>
      <a-tab-pane key="basePowderInspection" tab="基粉检验信息" :force-render="true">
        <inspection ref="basePowderInspectionComponent" />
      </a-tab-pane>
      <a-tab-pane key="semiProInspection" tab="半成品检验信息" :force-render="true">
        <inspection ref="semiProInspectionComponent" />
      </a-tab-pane>
      <a-tab-pane key="finishedInspection" tab="成品检验信息" :force-render="true">
        <inspection ref="finishedInspectionComponent" />
      </a-tab-pane>
      <a-tab-pane key="packagereport" tab="包装报工信息" :force-render="true">
        <packagereport ref="packagereportComponent" />
      </a-tab-pane>
      <a-tab-pane key="proInbound" tab="成品入库信息" :force-render="true">
        <inbound ref="proInboundComponent" />
      </a-tab-pane>
      <a-tab-pane key="proFinalInspection" tab="成品入库终检信息" :force-render="true">
        <confirm ref="proFinalInspectionComponent" />
      </a-tab-pane>
      <a-tab-pane key="proOutbound" tab="成品出库信息" :force-render="true">
        <outbound ref="proOutboundComponent" />
      </a-tab-pane>
      <a-tab-pane key="conformance" tab="不合格信息" :force-render="true">
        <conformance ref="conformanceComponent" />
      </a-tab-pane>
      <a-tab-pane key="routingInspection" tab="巡检信息" :force-render="true">
        <routing ref="routingInspectionComponent" />
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { getAction } from '@api/manage'
import Inbound from './modules/inbound.vue'
import Confirm from './modules/confirm.vue'
import Outbound from './modules/outbound.vue'
import Feeding from './modules/feeding.vue'
import Workshopplan from './modules/workshopplan.vue'
import Formulalist from './modules/formulalist.vue'
import Formulanotice from './modules/formulanotice.vue'
import Packaging from './modules/packaging.vue'
import Proprocess from './modules/proprocess.vue'
import Inspection from './modules/inspection.vue'
import Conformance from './modules/conformance.vue'
import Routing from './modules/routing.vue'
import Packagereport from './modules/packagereport.vue'

export default {
  name: 'traceReverseList',
  components: {
    Inbound,
    Confirm,
    Outbound,
    Feeding,
    Workshopplan,
    Formulalist,
    Formulanotice,
    Packaging,
    Proprocess,
    Inspection,
    Conformance,
    Routing,
    Packagereport,
  },
  data() {
    return {
      description: '反向追溯页面',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      batchNumber: '',
      model: {
        materialCode: '',
        materialName: '',
        specificationModel: '',
        unit: '',
      },
      activeKey: 'formula',
      url: {
        list: '/wms/inventory/material',
      },
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    materialSearch() {
      this.model.materialCode = ''
      this.model.materialName = ''
      this.model.specificationModel = ''
      this.model.unit = ''
      if (this.batchNumber) {
        getAction(this.url.list, { batchNumber: this.batchNumber }).then((res) => {
          if (res.success) {
            let minfo = res.result || []
            this.model.materialCode = minfo.materialCode || ''
            this.model.materialName = minfo.materialName || ''
            this.model.specificationModel = minfo.specificationModel || ''
            this.model.unit = minfo.unitText || ''
            this.activeKey = 'formula'
            this.handleChangeTab()
          }
        })
      }
    },
    handleChangeTab() {
      switch (this.activeKey) {
        case 'formula':
          if (this.$refs.formulalistComponent) {
            this.$refs.formulalistComponent.loadformulalistData(this.batchNumber)
          }
          break
        case 'formulanotice':
          if (this.$refs.formulanoticeComponent) {
            this.$refs.formulanoticeComponent.loadformulanoticeData(this.batchNumber)
          }
          break
        case 'packaging':
          if (this.$refs.packagingComponent) {
            this.$refs.packagingComponent.loadpackagingData(this.batchNumber)
          }
          break
        case 'proplan':
          if (this.$refs.workshopplanComponent) {
            this.$refs.workshopplanComponent.loadworkshopplanData(this.batchNumber)
          }
          break
        case 'proprocess':
          if (this.$refs.proprocessComponent) {
            this.$refs.proprocessComponent.loadProprocessData(this.batchNumber)
          }
          break
        case 'inbound':
          if (this.$refs.inboundComponent) {
            this.$refs.inboundComponent.loadInboundData(this.batchNumber, true)
          }
          break
        case 'confirm':
          if (this.$refs.confirmComponent) {
            this.$refs.confirmComponent.loadConfirmData(this.batchNumber, 'raw-material', true)
          }
          break
        case 'outbound':
          if (this.$refs.outboundComponent) {
            this.$refs.outboundComponent.loadOutboundData(this.batchNumber, true)
          }
          break
        case 'feeding':
          if (this.$refs.feedingComponent) {
            this.$refs.feedingComponent.loadFeedingData(this.batchNumber, true)
          }
          break
        case 'basePowderInspection':
          if (this.$refs.basePowderInspectionComponent) {
            this.$refs.basePowderInspectionComponent.loadInspectionData(this.batchNumber, 'base-powder')
          }
          break
        case 'semiProInspection':
          if (this.$refs.semiProInspectionComponent) {
            this.$refs.semiProInspectionComponent.loadInspectionData(this.batchNumber, 'semi-finished-product')
          }
          break
        case 'finishedInspection':
          if (this.$refs.finishedInspectionComponent) {
            this.$refs.finishedInspectionComponent.loadInspectionData(this.batchNumber, 'finished-product')
          }
          break
        case 'packagereport':
          if (this.$refs.packagereportComponent) {
            this.$refs.packagereportComponent.loadPackagereportData(this.batchNumber)
          }
          break
        case 'proInbound':
          if (this.$refs.proInboundComponent) {
            this.$refs.proInboundComponent.loadInboundData(this.batchNumber, false)
          }
          break
        case 'proFinalInspection':
          if (this.$refs.proFinalInspectionComponent) {
            this.$refs.proFinalInspectionComponent.loadConfirmData(this.batchNumber, 'finished-product-final', false)
          }
          break
        case 'proOutbound':
          if (this.$refs.proOutboundComponent) {
            this.$refs.proOutboundComponent.loadOutboundData(this.batchNumber, false)
          }
          break
        case 'conformance':
          if (this.$refs.conformanceComponent) {
            this.$refs.conformanceComponent.loadConformanceData(this.batchNumber)
          }
          break
        case 'routingInspection':
          if (this.$refs.routingInspectionComponent) {
            this.$refs.routingInspectionComponent.loadRoutingData(this.batchNumber)
          }
          break
        default:
          break
      }
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
